<style type="text/css">	
	div.thumb {
		float:left;
	}
	div.caption {
		padding-left:5px;
		font-size:10px;
	}
    .kich{
        border: 1px solid #cacaca;
        padding:2px;
        width:100px;
        text-align:center;
        background-color: #9C9AF9;
        color:#fff;
        cursor: pointer;   
    }
    .rev{
        border: 1px solid #cacaca;
        padding:2px;
        width:100px;
        text-align:center;
        background-color: #FF0224;
        color:#fff;
        cursor: pointer;
        
    }
    
	</style>

	<script type="text/javascript">

            function BrowseServer( startupPath, functionData )
            {
            	// You can use the "CKFinder" class to render CKFinder in a page:
            	var finder = new CKFinder();
            
            	// The path for the installation of CKFinder (default = "/ckfinder/").
            	finder.basePath = '../';
            
            	//Startup path in a form: "Type:/path/to/directory/"
            	finder.startupPath = startupPath;
            
            	// Name of a function which is called when a file is selected in CKFinder.
            	finder.selectActionFunction = SetFileField;
            
            	// Additional data to be passed to the selectActionFunction in a second argument.
            	// We'll use this feature to pass the Id of a field that will be updated.
            	finder.selectActionData = functionData;
            
            	// Name of a function which is called when a thumbnail is selected in CKFinder.
            	finder.selectThumbnailActionFunction = ShowThumbnails;
            
            	// Launch CKFinder
            	finder.popup();
            }
            
            // This is a sample function which is called when a file is selected in CKFinder.
            function SetFileField( fileUrl, data )
            {
            	document.getElementById( data["selectActionData"] ).value = fileUrl;
            }
            
            // This is a sample function which is called when a thumbnail is selected in CKFinder.
            function ShowThumbnails( fileUrl, data )
            {
            	// this = CKFinderAPI
            	var sFileName = this.getSelectedFile().name;
            	document.getElementById( 'thumbnails' ).innerHTML +=
            			'<div class="thumb">' +
            				'<img src="' + fileUrl + '" />' +
            				'<div class="caption">' +
            					'<a href="' + data["fileUrl"] + '" target="_blank">' + sFileName + '</a> (' + data["fileSize"] + 'KB)' +
            				'</div>' +
            			'</div>';
            
            	document.getElementById( 'preview' ).style.display = "";
            	// It is not required to return any value.
            	// When false is returned, CKFinder will not close automatically.
            	return false;
            }
	</script>
<!-- sua bai viet-->
<!-- script add them hinh anh-->	
<script>
var ii=1;
$(document).ready(function(){
   $('.kich').click(function(){    
    var insert = '<p><input id="xFilePath'+ii+'" name="img[]" type="text" size="60" /><input type="button" value="Tải lên" onclick="BrowseServer( \'Files:/\', \'xFilePath'+ii+'\' );" /><span class="rev">Xóa</span></p>';
    $(insert).appendTo('.inner');
    ii++;
   })
    $('.rev').live('click', function() { 
    $(this).parents('p').remove();    
   })
    
})

</script>
<!-- end script add them hinh anh-->
<!-- sua bai viet-->
<?php echo validation_errors(); ?>

<form method="POST" action="<?php echo base_url().'admin/xuly/sanpham/list/'.$this->uri->segment(5);?>">
    <div class="box_heading">
        <div class="icon">
        <img src="<?php echo base_url().'template/admin/images/icon_settings.png';?>"/> Sửa Tin tức ( <span style="color: red;"> * : không được để trống</span> )  <?php if(!empty($thongbao)){echo '<img src='.base_url().'template/admin/images/ok.png class="ok"><font color=red><b>'.$thongbao.'</b></font>';}?>
        </div>
        <div class="right">    
        <a href="<?php echo base_url().'admin/xuly/sanpham';?>">Hủy</a>
        </div>
    </div>
    
    <div class="box_noidung">
        <table class="form">
           <tr><td><font color=red>* </font>Tiêu đề</td><td><input type="text" size="40" value="<?php if(!empty($data)){echo $data->title;};?>" name="title"/></td></tr>
           <tr><td><font color=red>* </font>Alias</td><td><input type="text" size="40" value="<?php if(!empty($alias)){echo $alias->alias;};?>" name="alias"/>(Alias sẽ hiển thị trên url trình duyệt)</td></tr>
           <tr><td><font color=red>* </font>Danh mục</td><td>
             <script>
                $(document).ready(function(){
                     var parentid = '<?php if(!empty($data)){echo $data->category;};?>';
                        $('#'+parentid).attr('selected', 'selected');          
                });           
                </script>
                <select name="category">    
                <?php if($cat) {
                    echo $cat['category'];
                }?>                                  
                   
                </select> 
                </td></tr> 
           <tr><td><font color=red>* </font>Model</td><td><input type="text" size="40" value="<?php if(!empty($data)){echo $data->model;};?>" name="model"/></td></tr>
           
            <tr><td><font color=red>* </font>Trạng thái</td><td>
                <select name="publish">                                            
                  <option <?php if(!empty($data)){if($data->publish=='1')echo 'selected="selected"';} ?> value='1'>Hiện</option>';
                  <option <?php if(!empty($data)){if($data->publish=='0')echo 'selected="selected"';} ?> value='0'>Ẩn</option>';                                              
                </select> 
                </td></tr>
            <tr><td><font color=red>* </font>Ảnh đại diện</td><td>
                <p>
                    <input id="xFile" name="image" type="text" size="60" value="<?php if(!empty($data)){echo $data->image;};?>" />
                    <input type="button" value="Tải lên" onclick="BrowseServer( 'Files:/', 'xFile' );" />
                    <img src="<?php if(!empty($data)){echo $data->image;};?>" width=20px height=20px/>
                    <!--input type="text" id="xFilePath" name="image"  size="53" class="medium" value="<?php if(!empty($data)){echo $data->image;} ?>" />
                    <input type="button" value="Tải ảnh lên" onclick="BrowseServer();" style="background-color: #E5E3E3;background-image: url('../../resources/images/button.png')" /-->
                </p>
                <div class="kich">Thêm Hình ảnh</div>
                    <div class="inner">
                    <?php 
                    if(!empty($data->img)){
                        $imag = explode (',',$data->img);
                        foreach ($imag as $imag){
                            echo '
                                <p>
                                    <input id="xFilePath" name="img[]" type="text" size="60" value="'.$imag.'" />
                                    <input type="button" value="Tải lên" onclick="BrowseServer( \'Files:/\', \'xFilePath\' );" />
                                    <span class="rev">Xóa</span>
                                    <img src="'.$imag.'" width=20px height=20px/>
                                </p>
                            ';
                        }
                        };
                    ?>
                    </div>
            </td></tr>
            <tr><td></font>Meta Description</td><td><textarea rows="2" cols="40" name="metades"><?php if(!empty($data)){echo $data->metades;};?></textarea></td></tr>
            <tr><td></font>Meta Keywords</td><td><textarea rows="2" cols="40" name="metakey"><?php if(!empty($data)){echo $data->metakey;};?></textarea></td></tr>
            <tr><td><font color=red>* </font>Tóm tắt nội dung</td><td><textarea rows="5" cols="40" name="introtext" id="soanthao"><?php if(!empty($data)){echo $data->introtext;};?></textarea></td></tr>
            <tr><td><font color=red>* </font>Nội dung</td><td><textarea rows="5" cols="40" name="fulltext" id="soanthao2"><?php if(!empty($data)){echo $data->fulltext;};?></textarea></td></tr>
            <tr><td></font>Thứ tự</td><td><input type="text" size="40" value ="<?php if(!empty($data)){echo $data->order;};?>"/></td></tr>
            <tr><td><font color=red>* </font>Success</td><td>
                <select name="type">                                            
                  <option <?php if(!empty($data)){if($data->success=='0')echo 'selected="selected"';} ?> value='0'>Giao diện</option>';
                  <option <?php if(!empty($data)){if($data->success=='1')echo 'selected="selected"';} ?> value='1'>Hoàn thành</option>';                                              
                </select> 
                </td></tr>
           <tr><td style="text-align: center;" colspan="2"><input class="guidulieu" type="submit" value="Lưu"/></td></tr>
        </table>
    </div>
</form>
    <script type="text/javascript">
       if ( typeof CKEDITOR == 'undefined' ){
        	document.write("khong");
        }
        else{
        	var editor = CKEDITOR.replace( 'soanthao' );  
            var editor2 = CKEDITOR.replace( 'soanthao2' );           
            CKFinder.setupCKEditor( editor, '<?php echo base_url();?>ckeditor/ckfinder/' ) ;  
            CKFinder.setupCKEditor( editor2, '<?php echo base_url();?>ckeditor/ckfinder/' ) ;                  	
        }
    </script>
<!--end sua bai viet-->